package com.luo.chengrui.module.crbpm.controller.admin.definition;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.luo.chengrui.module.crbpm.controller.admin.definition.vo.modelactivity.ModelActivityPageReqVO;
import com.luo.chengrui.module.crbpm.controller.admin.definition.vo.modelactivity.ModelActivityRespVO;
import com.luo.chengrui.module.crbpm.convert.definition.ModelActivityConvert;
import com.luo.chengrui.module.crbpm.dal.dataobject.definition.ModelActivityDO;
import com.luo.chengrui.module.crbpm.service.definition.ModelActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 流程模型正式版环节")
@RestController
@RequestMapping("/crbpm/model-activity")
@Validated
public class ModelActivityController {

    @Resource
    private ModelActivityService modelActivityService;

    @GetMapping("/get")
    @Operation(summary = "获得流程模型正式版环节")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crbpm:model-activity:query')")
    public CommonResult<ModelActivityRespVO> getModelActivity(@RequestParam("id") String id) {
        ModelActivityDO modelActivity = modelActivityService.getModelActivity(id);
        return success(ModelActivityConvert.INSTANCE.convert(modelActivity));
    }

    @GetMapping("/list")
    @Operation(summary = "获得流程模型正式版环节列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('crbpm:model-activity:query')")
    public CommonResult<List<ModelActivityRespVO>> getModelActivityList(@RequestParam("ids") Collection<String> ids) {
        List<ModelActivityDO> list = modelActivityService.getModelActivityList(ids);
        return success(ModelActivityConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得流程模型正式版环节分页")
    @PreAuthorize("@ss.hasPermission('crbpm:model-activity:query')")
    public CommonResult<PageResult<ModelActivityRespVO>> getModelActivityPage(@Valid ModelActivityPageReqVO pageVO) {
        PageResult<ModelActivityDO> pageResult = modelActivityService.getModelActivityPage(pageVO);
        return success(ModelActivityConvert.INSTANCE.convertPage(pageResult));
    }


}
